#include "AIRuleSetPackage.h"
#include "AIActor.h"

namespace ai
{
	namespace expr
	{
		namespace impl
		{
			AIValue getMemValue(AIActor* actor, unsigned int memKey)
			{
				return actor->getMemoryValue(memKey); 
			}
		}

		AIExpr getMemValue(unsigned int memKey)
		{ 
			return std::bind(&impl::getMemValue, std::placeholders::_1, memKey); 
		}

		AIExpr and( const AIExpr& a, const AIExpr& b )
		{
			return [a, b] (AIActor* actor) -> AIValue
			{
				AIValue first = a(actor);
				AIValue second = b(actor);

				if (first.type == AIValue::TypeBool)
					return AIValue(first.value.bValue && second.value.bValue);

				return AIValue();
			};
		}

		AIExpr less(const AIExpr& a, const AIExpr& b)
		{
			return [a, b] (AIActor* actor) -> AIValue
			{
				AIValue first = a(actor);
				AIValue second = b(actor);

				if (first.type == AIValue::TypeFloat)
					return AIValue(first.value.fValue < second.value.fValue);

				return AIValue(false);
			};
		}
	}
	void AIRuleSetPackage::run(AIActor* actor ) const
	{

	}

	AIRule::AIRule( const AIRule& other )
	{
		_memKey = other._memKey;
		_expression = other._expression;
	}


	void AIRuleSet::AddRule( const AIRule& rule )
	{
		_rules.push_back(rule);
	}

}